/*
 * @Author: your name
 * @Date: 2021-04-09 13:00:51
 * @LastEditTime: 2021-04-09 13:04:47
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \my-app-koa\client\src\common\PrivateRoute.js
 */
import React from 'react'
import { Route, Redirect } from 'react-router-dom';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';

const PrivateRoute = ({ component: Component, auth, ...rest }) => (
  <Route
    {...rest}
    render={props => auth.isAuthenticated ? <Component {...props} /> : <Redirect to="/login" />} />
)
PrivateRoute.prototype = {
  auth: PropTypes.object.isRequired
}
const mapStateToProps = state => ({
  auth: state.auth
})
export default connect(mapStateToProps)(PrivateRoute)
// import React from 'react'
// import { Route, Redirect } from 'react-router-dom';
// import { connect } from 'react-redux';
// import PropTypes from 'prop-types';

// const PrivateRoute = ({ component: Component, auth, ...rest }) => (
//   <Route
//     {...rest}
//     render={props => auth.isAuthenticated === true ? <Component {...props} /> : <Redirect to='/login' />}
//   />
// )

// PrivateRoute.prototype = {
//   auth: PropTypes.object.isRequired
// }

// const mapStateToProps = state => ({
//   auth: state.auth
// })

// export default connect(mapStateToProps)(PrivateRoute)
